package System_code;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-08-02
 * Time: 15:19
 */
public class Demo15 {
     volatile public static int test = 0;  //定义一个整形变量

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while (test == 0) {
                //啥都不干
            }
            System.out.println("线程1执行完了");  //循环结束, 则打印这个语句
        });

        Thread t2 = new Thread(() -> {
            Scanner in = new Scanner(System.in);
            System.out.println("输入 ->"); //在线程2中偷偷改变 test 的值
            test = in.nextInt();
        });
        t1.start();
        t2.start();

        try {
            t1.join(); //线程等待
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
